package com.qixin.modules.eaStandard.controller;

import com.qixin.modules.eaStandard.service.IEaStandardService;
import com.qixin.modules.eaStandard.vo.EaEntertainCheckVo;
import com.qixin.modules.eaStandard.vo.EaStandardVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author:wly
 * @Date:2021/9/30
 * @Describtion: 标准校验访问层
 */
@Api(tags="app校验标准")
@RestController
@RequestMapping("/app/api/eaStandard")
@Slf4j
public class ApiEaStandardController {
    @Autowired
    private IEaStandardService iEaStandardService;

    /**
     *   校验发票报销标准
     *
     * @param eaStandardVo
     * @return
     */
    @AutoLog(value = "校验发票报销标准")
    @ApiOperation(value="校验发票报销标准", notes="校验发票报销标准")
    @PostMapping(value = "/check")
    public Result check(@RequestBody EaStandardVo eaStandardVo) {
        //判断报销是否合规
        Map<String,Object> returnMap = iEaStandardService.check(eaStandardVo);
        String code = returnMap.get("code") !=null ? returnMap.get("code").toString() : "";
        if(code.equals("-1")){
            returnMap.put("reversalAmount",0);
            returnMap.remove("code");
            return Result.error(returnMap);
        }else{
            returnMap.remove("code");
            return Result.OK(returnMap);
        }
    }

    /**
     *   校验招待费报销标准
     *
     * @param eaEntertainApplyIdVo
     * @return
     */
    @AutoLog(value = "校验招待费报销标准")
    @ApiOperation(value="校验招待费报销标准", notes="校验招待费报销标准")
    @PostMapping(value = "/checkEntertain")
    public Result checkEntertain(@RequestBody EaEntertainCheckVo eaEntertainApplyIdVo) {
        //判断报销是否合规
        Map<String,Object> returnMap = iEaStandardService.checkEntertain(eaEntertainApplyIdVo);
        returnMap.remove("code");
        return Result.OK(returnMap);
    }

    /**
     *   通讯费校验发票报销标准
     *
     * @param eaStandardVo
     * @return
     */
    @AutoLog(value = "通讯费校验发票报销标准")
    @ApiOperation(value="通讯费校验发票报销标准", notes="通讯费校验发票报销标准")
    @PostMapping(value = "/check_tx")
    public Result check_tx(@RequestBody EaStandardVo eaStandardVo) {
        //判断报销是否合规
        Map<String,Object> returnMap = iEaStandardService.check_tx(eaStandardVo);
        String code = returnMap.get("code") !=null ? returnMap.get("code").toString() : "";
        if(code.equals("-1")){
            returnMap.put("reversalAmount",0);
            returnMap.remove("code");
            return Result.error(returnMap);
        }else{
            returnMap.remove("code");
            return Result.OK(returnMap);
        }
    }



}
